/*
  jQuery Plugin CheckData  version: 0.000001	
  By JackRebel @2016	
  No Copyright！ you happy jiu good！ 
*/
(function ($) {
    $.fn.CheckData = function () {
        var CheckData = {
            Error: "",
            //***非空验证***//
            _require: function (item) {
                var require = item.attr("require");
                if (require === "true" && require !== undefined && require !== null && item.val() === "") {
                    CheckData.Error += "-" + item.attr("errormsg") + "\n";
                    item.focus();
                }
            },
			//***正整数验证***//
            _isNum: function (item) {
                var reg = /^\d+$/;
                var number = item.attr("number");
                if (number === "true" && number !== undefined && number !== null && $.trim(item.val()).match(reg) === null) {
                    CheckData.Error += "-" + item.attr("errormsg") + "\n";
                    item.focus();
                }
            },
            //***最小值验证***//
            _min: function (item) {
                var min = item.attr("min");
                if (min !== undefined && min !== null && item.val() < parseInt(min)) {
                    CheckData.Error += "-" + item.attr("errormsg") + "\n";
                    item.focus();
                }
            },
            //***最大值验证***//
            _max: function (item) {
                var max = item.attr("max");
                if (max !== undefined && max !== null && item.val() > parseInt(max)) {
                    CheckData.Error += "-" + item.attr("errormsg") + "\n";
                    item.focus();
                }
            },
            //***国内手机号验证***//
            _ismobile: function (item) {
                var reg = /^1[3456789]\d{9}$/;
                var ismobile = item.attr("ismobile");
			 
                 if (ismobile === "true" && ismobile !== undefined && ismobile !== null && reg.test(item.val())===false && item.val()!=="") {
                    CheckData.Error += "-" + item.attr("errormsg") + "\n";
                    item.focus();
                }
            },
			//***邮箱验证***//
            _isEmail: function (item) {
                var reg = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}$/;
                var isemail = item.attr("isemail");
                if (isemail === "true" && isemail !== undefined && isemail !== null && $.trim(item.val()).match(reg) === null && item.val()!=="") {
                    CheckData.Error += "-" + item.attr("errormsg") + "\n";
                    item.focus();
                }
            },
			//***正则验证***//
            _regex: function (item) {
                var regex = new RegExp(item.attr("regex"));
				 // var regex = item.attr("regex") ;
                if (regex !== undefined && regex !== null && $.trim(item.val()).match(regex) === null && item.val()!=="") {
                    CheckData.Error += "-" + item.attr("errormsg") + "\n";
                    item.focus();
                }
            },
			//***字数验证***//
            _isDataType: function (item) {			 
				 var datatype = item.attr("datatype");
                if (datatype !== undefined && datatype !== null &&  item.val()!=="") {					
					 var tmp=datatype.split('-');
					 if(item.val().length<tmp[0]||item.val().length>tmp[1]){
						CheckData.Error += "-" + item.attr("errormsg") + "\n";
						item.focus();
					 }
                }
            },
			//***两次复验证***//
            _reCheck: function (item) {			 
				 var recheck = item.attr("recheck");				 
                 if (recheck !== undefined && recheck !== null &&  item.val()!=="") {					 
					 if(item.val() !== $(recheck).val()){
						CheckData.Error += "-" + item.attr("errormsg") + "\n";
						item.focus();
					 }
                }
            }
        };	
			CheckData.Error = "";
			this.find("input").each(function (index, item) {
            CheckData._regex($(item));	
            CheckData._reCheck($(item)); 
            CheckData._isDataType($(item)); 
            CheckData._isEmail($(item));
            CheckData._require($(item));
            CheckData._min($(item));
            CheckData._max($(item));
            CheckData._isNum($(item));
			CheckData._ismobile($(item)); 
        });
        this.data("result", CheckData.Error == "" ? true : false).data("info", CheckData.Error);
        return this;
    }
})(jQuery)